<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>购物车结算-{$tpshop_config['shop_info_store_title']}</title>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/tpshop.css"/>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/myaccount.css"/>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/jh.css"/>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/jquery.datetimepicker.css"/>
    <script src="__STATIC__/js/jquery-1.11.3.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="__STATIC__/js/jquery.datetimepicker.full.js" type="text/javascript" charset="utf-8"></script>
    <script src="__PUBLIC__/js/layer/layer.js"></script>
    <script src="__PUBLIC__/js/global.js" type="text/javascript" charset="utf-8"></script>
    <script src="__PUBLIC__/js/md5.min.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=3qkFf2G2rUbWKsNYmc2dDvL7"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.js"></script>
    <link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.css" />
</head>
<body>
<!--顶部广告-s-->
<adv pid="1" limit="1" item="v">
    <div class="topic-banner" style="background: #f37c1e;">
        <div class="w1224">
            <a href="{$v.ad_link}">
                <img src="{$v[ad_code]}"/>
            </a>
            <i onclick="$('.topic-banner').hide();"></i>
        </div>
    </div>
</adv>
<!--顶部广告-e-->
<!--header-s-->
<div class="sett_hander p">
    <include file="public/sign-header"/>
    <div class="nav-middan-z p">
        <div class="header w1224">
            <div class="ecsc-logo fon_gwcshcar">
                <a href="/" class="logo"> <img src="{$tpshop_config['shop_info_store_logo']|default='__PUBLIC__/static/images/logo/pc_home_logo_default.png'}" style="width: 161px;height: 58px;"></a>
                <span>购物车</span>
            </div>
            <div class="liucsell">
                <div class="line-flowpath">
                    <span class="green"><i class="las-flo"></i><em>1、我的购物车</em></span>
                    <span class="green now"><i class="las-flo2"></i><em>2、填写核对订单信息</em></span>
                    <span><i class="las-flo3"></i><em>3、成功提交订单</em></span>
                </div>
            </div>
        </div>
    </div>
</div>
<!--header-e-->
<form name="cart2_form" id="cart2_form" method="post" autocomplete="off">
    <input type="hidden" id="address_id" name="address_id" value="">
    <input type="hidden" id="order_invoice_title" name="invoice_title" value="">
    <input type="hidden" id="order_taxpayer" name="taxpayer" value="">
    <input type="hidden" name="goods_num" value="{$Request.param.goods_num}">
    <input type="hidden" name="pre_sell_id" value="{$preSell.pre_sell_id}"/>
    <input type="hidden" name="user_note" value="">
</form>
<div class="fillorder">
    <div class="w1224">
        <p class="tit">填写并核对订单信息</p>

        <div class="spriteform" id="ajax_address"></div>
    </div>
</div>
<!--编辑地址弹窗-s--->
<div class="ui-dialog infom-dia" id="address_dialog" style="width: 700px">
    <form id="address_form">
        <input name="address_id" type="hidden" value="0">

        <div class="ui-dialog-title">
            <span>新增收货地址</span>
            <a class="ui-dialog-close" id="address_dialog_close" title="关闭">
                <span class="ui-icon ui-icon-delete"></span>
            </a>
        </div>
        <div class="ui-dialog-content" style="height: 600px;width: 700px">
            <div class="invoice-dialog">
                <div class="zinvoice-tips">
                    <!--<span class="tip-cont">错误信息</span>-->
                </div>
                <div class="ui-switchable-panel">
                    <div class="invoice_title p">
                        <span class="label"><span class="red">*</span>收货人：</span>

                        <div class="fl">
                            <input class="invoice_tt" name="consignee" type="text" value="" maxlength="12"/>
                            <span class="err" id="err_consignee"></span>
                        </div>
                    </div>
                    <div class="invoice_title p">
                        <span class="label"><span class="red">*</span>手机或固定电话：</span>

                        <div class="fl">
                            <input class="invoice_tt" name="mobile" type="text" value=""
                                   placeholder="固话号码格式:xx-xx(例如: 0755-86140485)" maxlength="15"/>
                            <span class="err" id="err_mobile"></span>
                        </div>
                    </div>
                    <div class="invoice_title p">
                        <span class="label"><span class="red">*</span>收货地址：</span>
                        <span class="err" id="err_province"></span>
                        <span class="err" id="err_city"></span>
                        <span class="err" id="err_district"></span>
                        <select class="di-bl fl seauii" name="province" id="province" onChange="get_city(this)">
                            <option value="0">请选择</option>
                        </select>
                        <select class="di-bl fl seauii" name="city" id="city" onChange="get_area(this)">
                            <option value="0">请选择</option>
                        </select>

                        <select class="di-bl fl seauii" name="district" id="district" onChange="get_twon(this)">
                            <option value="0">请选择</option>
                        </select>

                        <select class="di-bl fl seauii" name="twon" id="twon" style="display:none;">
                        </select>
                    </div>
                    <div class="invoice_title p">
                        <span class="label"><span class="red">*</span>详细地址：</span>
                        <span class="err" id="err_address"></span>

                        <div class="fl">
                            <input class="invoice_tt" name="address" type="text" placeholder="详细地址" maxlength="100"/>
                        </div>
                    </div>
                    <div class="invoice_title p">
                        <span class="label">邮编：</span>

                        <div class="fl">
                            <input class="invoice_tt" name="zipcode" type="text" value=""
                                   onKeyUp="this.value=this.value.replace(/[^\d]/g,'')" maxlength="10"/>
                        </div>
                    </div>
                    <div class="invoice_title p">
                        <span class="label">&nbsp;</span>

                        <div class="fl">
                            <div class="op-btns  invoice_sendwithgift">
                                <a id="address_submit" class="btn-1">保存</a>
                                <a onclick="$('#address_dialog_close').trigger('click');" class="btn-9">取消</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<!--编辑地址弹窗-e--->
<div class="ui-mask" id="address_dialog_mask"></div>
<!--上门自提和快速配送切换 s-->
<div class="w1224 z-parkage-pc p">
    <span class="paragraph "><i class="ddd"></i> 配送方式</span>
    <ul class="z-parkage-pc-ul p">
        <li class="fl z-parkage-li" id="express_delivery">快递配送<span></span></li>
    </ul>
    <div class="dis-modes-li p" id="express_delivery_modes">
        <div class="shipment">
            <div class="fore1 p">
                <span class="mode-label">配送时间：</span>

                <div class="mode-infor hover-y">
                    <p><label>工作日、双休日与节假日均可送货</label></p>
                    <!--<p><label><input type="checkbox" name="" value="" /> 双休日、假日送</label></p>-->
                </div>
            </div>
        </div>
        <div class="standard_wei buy-remarks p">
            <span>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注 :</span>
            <textarea class="user_note_txt fl" maxlength="50" placeholder="最多输入50个字"></textarea>
        </div>
    </div>
</div>
<div class="sendgoodslist z-parkage-cont">
    <div class="w1224">
        <div class="top_leg p ma-to-20">
            <span class="paragraph fl"><i class="ddd"></i>送货清单</span>
            <a class="newadd fr hover-y">
                <i class="las-warning"></i>价格说明
                <div class="pairgoods">
                    <p class="tit">因可能存在系统缓存、页面更新导致价格变动异常等不确定性情况出现，商品售价以本结算页商品价格为准；如有疑问，请您立即联系销售商咨询</p>
                </div>
            </a>
        </div>
        <!--商品列表-s-->
        <div class="shopping-listpay">
            <div class="goods-list-ri">
                <div class="goodsforma">
                    <div class="goods-last-suit ma-to-10 p">
                        <div class="goods-suit-tit" style="display: none">
                            <span class="sales-icon">订单优惠</span>
                            <strong id="store_order_prom_title"></strong>
                            <!--<span class="mlstran">&nbsp;返现：<em>￥20.00</em></span>-->
                        </div>
                    </div>
                    <ul class="buy-shopping-list">
                        <volist name="cartList" id="cart">
                            <li>
                                <div class="goods-extra clearfix">
                                    <div class="p-img">
                                        <a target="_blank"
                                           href="{:U('Home/Goods/goodsInfo',array('id'=>$cart['goods_id']))}">
                                            <img src="{$cart.goods_id|goods_thum_images=102,102}" alt="">
                                        </a>

                                        <div class="p-img-tips" id="goods_shipping_img_{$cart[goods_id]}"
                                             style="display: none">暂无商品
                                        </div>
                                    </div>
                                    <div class="goods-msg clearfix">
                                        <div class="goods-msg-gel">
                                            <div class="tp-cart-goods-name">
                                                <a href="{:U('Home/Goods/goodsInfo',array('id'=>$cart['goods_id']))}"
                                                   target="_blank">{$cart.goods_name}</a>
                                            </div>
                                            <ul class="tp-cart-goods-mes">
                                                <li class="tp-c-red1">{$cart[spec_key_name]}</li>
                                                <li>
                                                    <span>x{$cart.goods_num}</span>
                                                    <span class="tp-bold tp-c-red1">￥ {$cart.member_goods_price}</span>
                                                </li>
                                                <li>
                                                    <span class="p-state"
                                                          id="goods_shipping_title_{$cart[goods_id]}">有货</span>
                                                    <span class="tp-c-red1">{$cart[goods][weight]}g</span>
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                    <div class="msp_return">
                                        <p class="guarantee-item">
                                            <!--   <i class="return7"></i><span class="f_blue">支持七天无理由退货</span>
                                               <i class="return7 return7-dark"></i><span class="f_dark">不支持七天无理由退货</span>-->
                                        </p>
                                        <!--<p class="btn-check-date"><i class="yb-h-gwc return7"></i><span class="f_blue f-999">选延保</span></p>-->
                                    </div>
                                </div>
                            </li>
                        </volist>
                    </ul>
                </div>
            </div>
        </div>
        <!--商品列表-e-->
    </div>
</div>

<div class="addremark">
    <div class="w1224">
        <div class="top_leg p ma-to-20">
            <span class="paragraph fl"><i class="ddd"></i>发票信息</span>
        </div>
        <div class="invoice-cont ma-to-20" id="changeinfo">
            <span id="span1">普通发票（纸质）</span>
            <span id="span2">个人</span>
            <span id="span3">明细</span>
            <span id="span4" style="display:none">不开发票</span>
            <a onclick="invoice_dialog();" href="javascript:void(0);">修改</a>
        </div>
    </div>
</div>
<div class="order-summary p">
    <div class="w1224">
        <div class="statistic fr">
            <div class="list">
                <span><em class="ftx-01">{$Request.param.goods_num}</em> 件商品，<if condition="$preSell['deposit_price'] gt 0">订金<else/>商品金额</if>：</span>
                <em class="price">￥{$cartTotalPrice|number_format=2}</em>
            </div>
            <div class="list deposit_div" style="display: none">
                <span>尾款：</span>
                <em class="price" id="balance_price">￥0.00</em>
            </div>
        </div>
    </div>
</div>
<div class="trade-foot p">
    <div class="w1224">
        <div class="trade-foot-detail-com">
            <div class="fc-price-info">
                <span class="price-tit">应付总额：</span>
                <span class="price-num" id="payables">￥0.00</span>
            </div>
            <div class="fc-consignee-info">
                <span class="mr20">寄送至： <span id="address_info"></span></span>
                <span id="sendMobile">收货人：<span id="address_user"></span></span>
            </div>
        </div>
    </div>
</div>
<div class="submitorder_carpay p">
    <div class="w1224">
        <button type="submit" id="submit_order" class="checkout-submit" onclick="submit_order();">
            提交订单
        </button>
    </div>
</div>
<!--发票信息弹窗-s--->
<div class="ui-dialog infom-dia" id="invoice_dialog">
    <div class="ui-dialog-title">
        <span>发票信息</span>
        <a class="ui-dialog-close" id="invoice_dialog_close" title="关闭">
            <span class="ui-icon ui-icon-delete"></span>
        </a>
    </div>
    <div class="ui-dialog-content" style="height: 600px">
        <div class="invoice-dialog">
            <div class="draw-a-bill">
                <div class="tab-nav tab-nav-border  p" style="border-top:0px;">
                    <ul>
                        <div class="tab-nav-titles">
                            发票类型
                        </div>
                        <li>
                            <div class="item_select_t curtr">
                                <span>普通发票</span>
                                <b></b>
                            </div>
                        </li>
                    </ul>
                </div>
                <div class="zinvoice-tips zinvoice-conts">
                    <i>1</i>
	                <span class="tip-cont">开票金额不包优惠券和积分支付部分。
                        <!--<a target="_blank" class="newadd" href="">发票信息相关问题&gt;&gt;</a>--></span>
                    <i>2</i>
                    <span class="tip-cont">开单位抬头发票须填写纳税人识别号，以免影响报销</span>
                </div>
                <div class="ui-switchable-panel">
                    <div class="switchable-wrap" >
                        <div class="invoice_title p">
                            <span class="label">发票抬头：</span>
                            <div class="fl">
                                <a onclick="hidediv()"  class="setlesbtn setles-bg" id="personage">个人 <b></b></a>
                                <a onclick="togglediv()" class="setlesbtn" id="addinvoice" href="javascript:void(0);" >单位<b></b></a>
                            </div>
                        </div>
                        <div class="invoice_title p">

                            <div id="ratepaying" style="display:none" class="invoice_title ">
                                <div class="p">
                                    <span class="label">抬头内容&nbsp;&nbsp;&nbsp;：</span>
                                    <div class="fl">
                                        <input class="invoice_tt m-b-20" type="text" placeholder="请输入单位名称" value="" id="invoice_title"/>
                                    </div>
                                </div>
                                <div class="p">
                                    <span class="label">纳税人识别号：</span>
                                    <div class="fl">
                                        <input class="invoice_tt" placeholder="请输入纳税识别号" type="text" value="" id="taxpayer"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="invoice_title p">
                        <span class="label">发票内容：</span>
                        <input type="hidden" name="invoice_desc" id="invoice_desc" value="">

                        <div class="fl">
                            <div class="tab-nav p">
                                <ul id="invoice_class">
                                    <li>
                                        <div class="item_select_t curtr" id="detail_invoice">
                                            <span>商品明细</span>
                                            <b></b>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="item_select_t" id="type_invoice">
                                            <span>商品类别</span>
                                            <b></b>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="item_select_t" id="no_invoice">
                                            <span>不开发票</span>
                                            <b></b>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="invoice_title p">
                <div class="op-btns-warp">
                    <div class="op-btns  invoice_sendwithgift">
                        <a id="invoiceBtn" class="btn-1">保存</a>
                        <a onclick="$('#invoice_dialog_close').trigger('click');" class="btn-9">取消</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--发票信息弹窗-e--->
<div class="ui-mask" id="invoice_mask"></div>
<!--footer-s-->
<img class="rabbit" src="/public/images/qw.gif" alt="">

<div class="mask-filter-div"></div>
<include file="public/footer"/>
<!--footer-e-->
<script type="text/javascript">
    $(document).ready(function () {
        ajax_address();
        get_province();
        self_motion_load();
    });
    ;
    //点击收货地址
    $(function () {
        $(document).on("click", '.addressItem .item_select_t', function (e) {
            $('#express_delivery').trigger('click');
            //如果本来没被选中
            if (!$(this).hasClass('curtr')) {
                $('.addressItem').find('.item_select_t').each(function () {
                    $(this).removeClass('curtr');
                })
                $(this).addClass('curtr');
                initAddress();
            }
        })
    })
    //支付方式更多
    $(function () {
        $('.lastist').click(function () {
            if ($(this).hasClass('addlastist')) {
                $(this).removeClass('addlastist');
                $(this).find('span').text('更多');
                $(this).parents('.payment-list').find('.solwpah').removeClass('moreshow');
            } else {
                $(this).addClass('addlastist');
                $(this).find('span').text('收起');
                $(this).parents('.payment-list').find('.solwpah').addClass('moreshow');
            }
        })
    })

    //对应商品
    $(function () {
        $(document).on('click', '.hover-y', function () {
            if ($(this).find('.pairgoods').is(":hidden")) {
                $(this).find('.pairgoods').show();
            } else {
                $(this).find('.pairgoods').hide();
            }

        });
    })

    /**
     * ajax 获取当前用户的收货地址列表
     */
    function ajax_address() {
        $.ajax({
            url: "{:U('Home/Cart/ajaxAddress')}", //+tab,
            success: function (data) {
                $("#ajax_address").empty().append(data);
                if (data != '') {
                    initAddress();
                }
            }
        });
    }
    //设置收货地址
    function initAddress() {
        var address_item = $('.addressItem').find('.curtr').parents('.addressItem');
        var address_id = address_item.attr('data-address-id');
        var address_name = address_item.find('.addr-name').attr('title');
        var address_tel = address_item.find('.addr-tel').attr('title');

        $('#address_info').html(address_item.find('.addr-info').attr('title'));
        if (address_name && address_tel) {
            $('#address_user').html(address_name + ' ' + address_tel);
        }
        $("input[name='address_id']").attr('value', address_id);
        if (address_item.length == 0) {
            $('#addNewAddress').trigger('click');
        } else {
            ajax_order_price(); // 计算订单价钱
        }
    }

    /**
     * 获取订单价格
     */
    function ajax_order_price() {
        $.ajax({
            type: "POST",
            url: "{:U('Home/Cart/pre_sell_place')}",
            dataType: 'json',
            data: $('#cart2_form').serialize(),
            success: function (data) {
                is_shipping_able = true;
                if (data.status != 1) {
                    layer.msg(data.msg, {icon: 2, time: 2000},function(){
                        // 登录超时
                        if (data.status == -100) {
                            location.href = "{:U('Home/User/login')}";
                        }
                    });
                    // 显示商品有货无货配送
                    for (v in data.result.goods_shipping) {
                        if (data.result.goods_shipping[v] != '' && data.result.goods_shipping[v] != null) {
                            if (data.result.goods_shipping[v].status == 1) {
                                goods_shipping(v, true);
                            } else {
                                goods_shipping(v, false);
                            }
                        }
                    }
                    return false;
                }
                if(data.result.deposit_price > 0){
                    $('.deposit_div').show();
                    $('#balance_price').text('￥' + data.result.balance_price.toFixed(2));
                }
                $("#payables").text('￥' + data.result.order_amount.toFixed(2));// 应付
            }
        });
    }

    function submit_order() {
        $('#submit_order').attr('disabled','disabled');
        $('.user_note_txt').each(function () {
            $("input[name='user_note']").attr('value', $(this).val());
        });
        var invoice_desc = $("#invoice_desc").val();
        $.ajax({
            type: "POST",
            url: "{:U('Home/Cart/pre_sell_place')}", //+tab,
            data: $('#cart2_form').serialize() + "&act=submit_order&invoice_desc="+invoice_desc, //
            dataType: "json",
            success: function (data) {
                // 当前人数过多 排队中
                if (data.status == -99) {
                    $('.mask-filter-div').show();
                    $('.rabbit').show();
                    setTimeout("submit_order()", 5000);
                    return false;
                } else {
                    // 隐藏排队
                    $('.mask-filter-div').hide();
                    $('.rabbit').hide();
                }

                if (data.status != 1) {
                    layer.msg(data.msg, {
                        icon: 2,
                        time: 1000 //2秒关闭（如果不配置，默认是3秒）
                    });
                    // 登录超时
                    if (data.status == -100) {
                        location.href = "{:U('Home/User/login')}";
                    }
                    return false;
                }
                layer.msg('订单提交成功!', {
                    icon: 1, // 成功图标
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function () { // 关闭后执行的函数
                    location.href = "/index.php?m=Home&c=Cart&a=cart4&order_sn=" + data.result; // 跳转到结算页
                });
            }
        });
    }

    $(document).on('keyup', '#pay_pwd', function () {
        var pay_pwd = md5($("input[name='auth_code']").val() + this.value);
        $('input[name="pay_pwd"]').val(pay_pwd);
    })
    //设置商品有货无货
    function goods_shipping(goods_id, is_have) {
        if (is_have == true) {
            $('#goods_shipping_img_' + goods_id).hide();
            $('goods_shipping_title_' + goods_id).removeClass('red').text('有货');
        } else {
            $('#goods_shipping_img_' + goods_id).show();
            $('#goods_shipping_title_' + goods_id).addClass('red').text('无货');
        }
    }
    //收货人信息
    $(function () {
        $(document).on("click", '.addr-switch', function (e) {
            if ($(this).hasClass('switch-on')) {
                $(this).removeClass('switch-on');
                $(this).find('span').text('更多地址');
                $('.consignee-list').css('height', '42px');
                var addressItem = $('.consignee-list').find('.curtr').parents('.addressItem');
                $('.consignee-list').find('ul').prepend(addressItem.clone(true));
                addressItem.remove();
            } else {
                $(this).addClass('switch-on');
                $(this).find('span').text('收起地址');
                $('.consignee-list').css('height', 'inherit');
            }
        })
    })
    //新增编辑地址
    $(function () {
        //新增编辑弹窗事件
        $(document).on("click", '.address_item', function (e) {
            var dh = $(document).height();
            var dw = $(document).width();
            $('#address_dialog_mask').height(dh).width(dw).show();
            $('#address_dialog').show();
            var address_id = $(this).data('address-id');
            if (address_id > 0) {
                $("input[name='address_id']").val(address_id);
                $.ajax({
                    type: "POST",
                    url: "{:U('Home/User/address')}",
                    data: {address_id: address_id},
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 1) {
                            $("input[name='consignee']").val(data.result.user_address.consignee);
                            $("input[name='address']").val(data.result.user_address.address);
                            $("input[name='mobile']").val(data.result.user_address.mobile);
                            $("input[name='zipcode']").val(data.result.user_address.zipcode);
                            var city_list_option_html = '<option value="0">请选择</option>';
                            var district_list_option_html = '<option value="0">请选择</option>';
                            var twon_list_option_html = '<option value="0">请选择</option>';
                            $.each(data.result.city_list, function (n, value) {
                                city_list_option_html += '<option value="' + value.id + '">' + value.name + '</option>';
                            });
                            $('#city').html(city_list_option_html).val(data.result.user_address.city);
                            $.each(data.result.district_list, function (n, value) {
                                district_list_option_html += '<option value="' + value.id + '">' + value.name + '</option>';
                            });
                            $('#district').html(district_list_option_html).val(data.result.user_address.district);
                            $.each(data.result.twon_list, function (n, value) {
                                twon_list_option_html += '<option value="' + value.id + '">' + value.name + '</option>';
                            });
                            if (data.result.twon_list.length > 0) {
                                $('#twon').html(twon_list_option_html).val(data.result.user_address.twon).show();
                            }
                            $("#province").val(data.result.user_address.province);
                        } else {
                            layer.open({icon: 2, content: data.msg, time: 1000});
                        }
                    }
                });
            } else {
                $("input[name='consignee']").val('');
                $("input[name='address_id']").val(0);
                $("input[name='address']").val('');
                $("input[name='mobile']").val('');
                $("input[name='zipcode']").val('');
                $("#province").val(0);
                $("#city").empty().html('<option value="0">请选择</option>');
                $("#district").empty().html('<option value="0">请选择</option>');
                $("#twon").empty().html('<option value="0">请选择</option>').hide();
            }
        })
        //关闭弹窗事件
        $(document).on("click", '#address_dialog_close', function (e) {
            $('#address_dialog_mask').hide();
            $('#address_dialog').hide();
            $('.err').hide();
        })
        //地址提交
        $(document).on("click", '#address_submit', function (e) {
            $.ajax({
                type: "POST",
                url: "{:U('Home/User/addressSave')}",
                data: $('#address_form').serialize(),
                dataType: 'json',
                success: function (data) {
                    if (data.status == 1) {
                        $('#address_dialog_close').trigger('click');
                        ajax_address();
                    } else {
                        layer.open({
                            icon: 2, content: data.msg, time: 1000, end: function () {
                                $.each(data.result, function (index, item) {
                                    $('#err_' + index).text(item).show();
                                });
                            }
                        });
                    }
                }
            });
        })
        //设置默认地址
        $(document).on("click", '.address_set_default', function (e) {
            var address_id = $(this).data('address-id');
            $.ajax({
                type: "POST",
                url: "{:U('Home/User/addressSetDefault')}",
                data: {address_id: address_id},
                dataType: 'json',
                success: function (data) {
                    if (data.status == 1) {
                        location.reload();
                    } else {
                        layer.open({icon: 2, content: data.msg, time: 1000});
                    }
                }
            });
        })
        //删除收货地址
        $(document).on("click", '.address_delete', function (e) {
            var address_id = $(this).data('address-id');
            $.ajax({
                type: "POST",
                url: "{:U('Home/User/addressDelete')}",
                data: {address_id: address_id},
                dataType: 'json',
                success: function (data) {
                    if (data.status == 1) {
                        ajax_address();
                    } else {
                        layer.open({icon: 2, content: data.msg, time: 1000});
                    }
                }
            });
        })
    })
    //获取省列表
    function get_province() {
        $.ajax({
            type: "GET",
            url: "{:U('Home/Api/getProvince')}",
            dataType: 'json',
            success: function (data) {
                if (data.status == 1) {
                    var option_html = '<option value="0">请选择</option>';
                    $.each(data.result, function (n, value) {
                        option_html += '<option value="' + value.id + '">' + value.name + '</option>';
                    });
                    $('#province').html(option_html);
                    $('#address_province').html(option_html);
                } else {
                    layer.msg(data.msg, {icon: 2});
                }
            }
        });
    }

</script>
<script type="text/javascript">
    //发票相关js效果
    function hidediv() {
        $("#addinvoice").removeClass("setles-bg");
        $("#personage").addClass("setles-bg");
        $('#adddiv').hide();
        $("#ratepaying").hide();
    }
    function togglediv() {
        $("#addinvoice").addClass("setles-bg");
        $("#personage").removeClass("setles-bg");
        $('#adddiv').toggle();
        $("#ratepaying").toggle();
    }
    $(document).on("click","#invoice_class li",function  () {
        $("#invoice_class li").find(".item_select_t ").removeClass("curtr");
        $(this).children(".item_select_t ").addClass("curtr");
        $("#invoice_desc").val($(this).find('span').text());
        if($("#no_invoice").hasClass("curtr")){
            $(".switchable-wrap").hide();
        }else {
            if($("#personage").hasClass("setles-bg")){
                $("#ratepaying").hide();
            }else{
                $("#ratepaying").show();
            }
            $(".switchable-wrap").show();
        }
    });

    //发票弹窗
    function invoice_dialog() {
        var dh = $(document).height();
        var dw = $(document).width();
        $('#invoice_mask').height(dh).width(dw);
        $('#invoice_dialog').show();
        $('#invoice_mask').show();
        self_motion_load();
    }
    function self_motion_load() {
        $.get("{:U('Cart/invoice')}", function (json) {
            var data = eval("(" + json + ")");
            if (data.status > 0) {
                if (data.result.invoice_title != "个人") {
                    $('#order_invoice_title').val(data.result.invoice_title);
                    $("#order_taxpayer").val(data.result.taxpayer);
                    $('#invoice_title').val(data.result.invoice_title);
                    $("#invoice_desc").val(data.result.invoice_desc);
                    $("#taxpayer").val(data.result.taxpayer);
                    $('#adddiv').show();
                    $("#addinvoice").addClass("setles-bg");
                    $("#personage").removeClass("setles-bg");
                    $("#ratepaying").css("display","block");
                }
                if (data.result.invoice_title == "个人") {
                    $("#addinvoice").removeClass("setles-bg");
                    $("#personage").addClass("setles-bg");
                }
                if (data.result.invoice_desc == "不开发票") {
                    $('#order_invoice_title').val("");
                    $("#order_taxpayer").val("");
                    $(".switchable-wrap").hide();
                    $("#span1,#span2,#span3").hide();
                    $("#span4").show();
                    $("#invoice_class li").find(".item_select_t ").removeClass("curtr");
                    $("#no_invoice").addClass("curtr");
                } else {
                    if(data.result.invoice_desc == "商品明细"){
                        $("#invoice_class li").find(".item_select_t ").removeClass("curtr");
                        $("#detail_invoice").addClass("curtr");
                    }else{
                        $("#invoice_class li").find(".item_select_t ").removeClass("curtr");
                        $("#type_invoice").addClass("curtr");
                    }
                    if (data.result.invoice_title != "") {
                        $('#order_invoice_title').val(data.result.invoice_title);
                        $("#order_taxpayer").val(data.result.taxpayer);
                        $('#invoice_desc').val(data.result.invoice_desc);
                        $('#span2').text(data.result.invoice_title);
                        $('#span3').text(data.result.invoice_desc);
                        $("#span4").hide();
                        $("#span1,#span2,#span3").show();
                    }
                    $("#invoice_title").css({"border": "2px solid #e4393c"});
                    $(".switchable-wrap").show();
                }
            } else {
                $('#order_invoice_title').val("");
                $("#order_taxpayer").val("");
                $("#span1,#span2,#span3").hide();
                $("#span4").show();
            }
        });
    }

    //关闭发票弹窗
    $(function () {
        $('#invoice_dialog_close').click(function () {
            $('#invoice_dialog').hide();
            $('#invoice_mask').hide()
        })
    });

    //保存发票
    $(function () {
        $(document).on('click', '#invoiceBtn', function () {
            var invoice_desc = $("#invoice_desc").val();
            if (!$('#ratepaying').is(":hidden")) {
                var invoice_title = $("#invoice_title").val();
            } else {
                var invoice_title = "个人";
            }
            $('#span2').text(invoice_title);
            $('#span3').text(invoice_desc);
            if (invoice_desc == "不开发票") {
                $("#span1,#span2,#span3").hide();
                $("#span4").show();
            } else {
                $("#span1,#span2,#span3").show();
                $("#span4").hide();
            }
            save_invoice() && $('#invoice_dialog_close').trigger('click');
        });
    });

    function save_invoice() {
        var invoice_title = $("#personage").val();
        var invoice_desc = $("#invoice_desc").val();
        var data = {invoice_title: "个人", invoice_desc: invoice_desc};
        if (!$('#ratepaying').is(":hidden") && invoice_desc != "不开发票") {
            invoice_title = $("#invoice_title").val();
            if (invoice_title.length == 0) {
                layer.msg("发票抬头不能为空", {icon: 2});
                return false;
            }
            var taxpayer = $("#taxpayer").val();
            if ((taxpayer.length == 15) || (taxpayer.length == 18) || (taxpayer.length == 20)) {
            } else {
                layer.msg("请输入正确的纳税人识别号！", {icon: 2});
                return;
            }
            var addressCode = taxpayer.substring(0, 6);
            // 校验地址码
            var check = checkAddressCode(addressCode);
            if (!check) {
                layer.msg("请输入正确的纳税人识别号(地址码)！", {icon: 2});
                return;
            }
            // 校验组织机构代码
            var orgCode = taxpayer.substring(6, 9);
            check = orgcodevalidate(orgCode);
            if (!check) {
                layer.msg("请输入正确的纳税人识别号(组织机构代码) ！", {icon: 2});
                return;
            }
            $('#order_taxpayer').val(taxpayer);
            $('#order_invoice_title').val(invoice_title);
            var data = {invoice_title: invoice_title, taxpayer: taxpayer, invoice_desc: invoice_desc};
        } else {
            $('#order_taxpayer').val("");
            $('#order_invoice_title').val("个人");
        }
        if (invoice_desc == "不开发票") {
            $('#order_invoice_title').val("");
            $('#order_taxpayer').val("");
            $("#span1,#span2,#span3").hide();
            $("#span4").show();
        } else {
            $('#span2').text($('#order_invoice_title').val());
            $('#span3').text(invoice_desc);
            $("#span4").hide();
            $("#span1,#span2,#span3").show();
        }
        $.post("{:U('Cart/save_invoice')}", data, function (json) {
            var data = eval("(" + json + ")");
            if(data.status==1){
                layer.open({icon: 1, content:'保存成功', time: 1000});
            }else{
                layer.open({icon: 2, content: '保存失败', time: 1000});
            }
        });
        return true;
    }
</script>
</body>
</html>